.class public final Lcom/burstly/lib/downloadtracker/DownloadTrackingManager;
.super Ljava/lang/Object;
.source "DownloadTrackingManager.java"

# interfaces
.implements Lcom/burstly/lib/feature/dtracker/IDownloadTracker;
.implements Ljava/util/concurrent/Callable;


# annotations
.annotation system Ldalvik/annotation/MemberClasses;
    value = {
        Lcom/burstly/lib/downloadtracker/DownloadTrackingManager$RequestCallback;
    }
.end annotation

.annotation system Ldalvik/annotation/Signature;
    value = {
        "Ljava/lang/Object;",
        "Lcom/burstly/lib/feature/dtracker/IDownloadTracker;",
        "Ljava/util/concurrent/Callable",
        "<",
        "Ljava/lang/Boolean;",
        ">;"
    }
.end annotation


# static fields
.field public static final TAG:Ljava/lang/String;

.field static sAppContext:Landroid/content/Context;

.field static volatile sDownloadInProgress:Z

.field private static sLog:Lcom/burstly/lib/util/LoggerExt;


# direct methods
.method static constructor <clinit>()V
    .locals 1

    .prologue
    .line 49
    const-class v0, Lcom/burstly/lib/downloadtracker/DownloadTrackingManager;

    invoke-virtual {v0}, Ljava/lang/Class;->getSimpleName()Ljava/lang/String;

    move-result-object v0

    sput-object v0, Lcom/burstly/lib/downloadtracker/DownloadTrackingManager;->TAG:Ljava/lang/String;

    return-void
.end method

.method public constructor <init>()V
    .locals 0

    .prologue
    .line 44
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    .line 71
    return-void
.end method

.method static synthetic access$000()Lcom/burstly/lib/util/LoggerExt;
    .locals 1

    .prologue
    .line 44
    sget-object v0, Lcom/burstly/lib/downloadtracker/DownloadTrackingManager;->sLog:Lcom/burstly/lib/util/LoggerExt;

    return-object v0
.end method

.method static isFileExist(Ljava/lang/String;Landroid/content/Context;)Z
    .locals 2
    .parameter "fileName"
    .parameter "context"

    .prologue
    .line 143
    const/4 v0, 0x0

    .line 145
    .local v0, openFileInput:Ljava/io/FileInputStream;
    :try_start_0
    invoke-virtual {p1, p0}, Landroid/content/Context;->openFileInput(Ljava/lang/String;)Ljava/io/FileInputStream;
    :try_end_0
    .catchall {:try_start_0 .. :try_end_0} :catchall_0
    .catch Ljava/io/FileNotFoundException; {:try_start_0 .. :try_end_0} :catch_0

    move-result-object v0

    .line 146
    const/4 v1, 0x1

    .line 152
    invoke-static {v0}, Lcom/burstly/lib/util/Utils;->closeStream(Ljava/io/Closeable;)V

    .line 154
    :goto_0
    return v1

    .line 148
    :catch_0
    move-exception v1

    .line 152
    invoke-static {v0}, Lcom/burstly/lib/util/Utils;->closeStream(Ljava/io/Closeable;)V

    .line 154
    const/4 v1, 0x0

    goto :goto_0

    .line 152
    :catchall_0
    move-exception v1

    invoke-static {v0}, Lcom/burstly/lib/util/Utils;->closeStream(Ljava/io/Closeable;)V

    throw v1
.end method


# virtual methods
.method public call()Ljava/lang/Boolean;
    .locals 3
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/lang/Exception;
        }
    .end annotation

    .prologue
    const/4 v1, 0x0

    .line 199
    sget-object v2, Lcom/burstly/lib/downloadtracker/DownloadTrackingManager;->sAppContext:Landroid/content/Context;

    invoke-static {v2}, Lcom/burstly/lib/util/Utils;->getDeviceId(Landroid/content/Context;)Ljava/lang/String;

    move-result-object v0

    .line 200
    .local v0, deviceId:Ljava/lang/String;
    if-eqz v0, :cond_1

    .line 201
    sget-object v2, Lcom/burstly/lib/downloadtracker/DownloadTrackingManager;->sAppContext:Landroid/content/Context;

    invoke-static {v0, v2}, Lcom/burstly/lib/downloadtracker/DownloadTrackingManager;->isFileExist(Ljava/lang/String;Landroid/content/Context;)Z

    move-result v2

    if-nez v2, :cond_0

    const/4 v1, 0x1

    :cond_0
    invoke-static {v1}, Ljava/lang/Boolean;->valueOf(Z)Ljava/lang/Boolean;

    move-result-object v1

    .line 203
    :goto_0
    return-object v1

    :cond_1
    invoke-static {v1}, Ljava/lang/Boolean;->valueOf(Z)Ljava/lang/Boolean;

    move-result-object v1

    goto :goto_0
.end method

.method public bridge synthetic call()Ljava/lang/Object;
    .locals 1
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/lang/Exception;
        }
    .end annotation

    .prologue
    .line 44
    invoke-virtual {p0}, Lcom/burstly/lib/downloadtracker/DownloadTrackingManager;->call()Ljava/lang/Boolean;

    move-result-object v0

    return-object v0
.end method

.method public declared-synchronized sendDTRequestIfNeeded(Landroid/content/Context;)V
    .locals 6
    .parameter "context"
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Lcom/burstly/lib/exception/WrongThreadException;
        }
    .end annotation

    .prologue
    .line 164
    monitor-enter p0

    :try_start_0
    invoke-virtual {p1}, Landroid/content/Context;->getApplicationContext()Landroid/content/Context;

    move-result-object v2

    sput-object v2, Lcom/burstly/lib/downloadtracker/DownloadTrackingManager;->sAppContext:Landroid/content/Context;

    .line 166
    invoke-static {p1}, Lcom/burstly/lib/constants/BurstlyProperties;->initProperties(Landroid/content/Context;)V

    .line 168
    invoke-static {}, Lcom/burstly/lib/util/Utils;->checkIsUiThread()V

    .line 170
    invoke-static {p1}, Lcom/burstly/lib/service/HostsProviderManager;->init(Landroid/content/Context;)V

    .line 171
    sget-object v2, Lcom/burstly/lib/downloadtracker/DownloadTrackingManager;->sLog:Lcom/burstly/lib/util/LoggerExt;

    if-nez v2, :cond_0

    .line 172
    invoke-static {}, Lcom/burstly/lib/util/LoggerExt;->getInstance()Lcom/burstly/lib/util/LoggerExt;

    move-result-object v2

    sput-object v2, Lcom/burstly/lib/downloadtracker/DownloadTrackingManager;->sLog:Lcom/burstly/lib/util/LoggerExt;

    .line 174
    :cond_0
    invoke-static {p1}, Lcom/burstly/lib/util/Utils;->getDeviceId(Landroid/content/Context;)Ljava/lang/String;

    move-result-object v0

    .line 175
    .local v0, deviceId:Ljava/lang/String;
    if-nez v0, :cond_1

    .line 176
    sget-object v2, Lcom/burstly/lib/downloadtracker/DownloadTrackingManager;->sLog:Lcom/burstly/lib/util/LoggerExt;

    sget-object v3, Lcom/burstly/lib/downloadtracker/DownloadTrackingManager;->TAG:Ljava/lang/String;

    const-string v4, "Can not send download tracking request because device id is null"

    const/4 v5, 0x0

    new-array v5, v5, [Ljava/lang/Object;

    invoke-virtual {v2, v3, v4, v5}, Lcom/burstly/lib/util/LoggerExt;->logError(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;

    .line 179
    :cond_1
    if-eqz v0, :cond_3

    sget-boolean v2, Lcom/burstly/lib/downloadtracker/DownloadTrackingManager;->sDownloadInProgress:Z

    if-nez v2, :cond_3

    .line 180
    invoke-static {}, Ljava/util/concurrent/Executors;->newSingleThreadExecutor()Ljava/util/concurrent/ExecutorService;
    :try_end_0
    .catchall {:try_start_0 .. :try_end_0} :catchall_0

    move-result-object v1

    .line 182
    .local v1, exec:Ljava/util/concurrent/ExecutorService;
    :try_start_1
    invoke-interface {v1, p0}, Ljava/util/concurrent/ExecutorService;->submit(Ljava/util/concurrent/Callable;)Ljava/util/concurrent/Future;

    move-result-object v2

    invoke-interface {v2}, Ljava/util/concurrent/Future;->get()Ljava/lang/Object;

    move-result-object v2

    check-cast v2, Ljava/lang/Boolean;

    invoke-virtual {v2}, Ljava/lang/Boolean;->booleanValue()Z

    move-result v2

    if-eqz v2, :cond_2

    .line 183
    const/4 v2, 0x1

    sput-boolean v2, Lcom/burstly/lib/downloadtracker/DownloadTrackingManager;->sDownloadInProgress:Z

    .line 184
    sget-object v2, Lcom/burstly/lib/downloadtracker/DownloadTrackingManager;->TAG:Ljava/lang/String;

    new-instance v3, Lcom/burstly/lib/downloadtracker/DownloadTrackingManager$RequestCallback;

    invoke-direct {v3, p1, v0}, Lcom/burstly/lib/downloadtracker/DownloadTrackingManager$RequestCallback;-><init>(Landroid/content/Context;Ljava/lang/String;)V

    invoke-static {p1, v0, v2, v3}, Lcom/burstly/lib/network/request/RequestManager;->makeDownloadTrackRequest(Landroid/content/Context;Ljava/lang/String;Ljava/lang/String;Lcom/burstly/lib/network/request/IRequestCallback;)Lcom/burstly/lib/network/request/AbortableAsyncTask;
    :try_end_1
    .catchall {:try_start_1 .. :try_end_1} :catchall_1
    .catch Ljava/lang/Exception; {:try_start_1 .. :try_end_1} :catch_0

    .line 192
    :cond_2
    :try_start_2
    invoke-interface {v1}, Ljava/util/concurrent/ExecutorService;->shutdownNow()Ljava/util/List;
    :try_end_2
    .catchall {:try_start_2 .. :try_end_2} :catchall_0

    .line 195
    .end local v1           #exec:Ljava/util/concurrent/ExecutorService;
    :cond_3
    :goto_0
    monitor-exit p0

    return-void

    .line 188
    .restart local v1       #exec:Ljava/util/concurrent/ExecutorService;
    :catch_0
    move-exception v2

    .line 192
    :try_start_3
    invoke-interface {v1}, Ljava/util/concurrent/ExecutorService;->shutdownNow()Ljava/util/List;
    :try_end_3
    .catchall {:try_start_3 .. :try_end_3} :catchall_0

    goto :goto_0

    .line 164
    .end local v0           #deviceId:Ljava/lang/String;
    .end local v1           #exec:Ljava/util/concurrent/ExecutorService;
    :catchall_0
    move-exception v2

    monitor-exit p0

    throw v2

    .line 192
    .restart local v0       #deviceId:Ljava/lang/String;
    .restart local v1       #exec:Ljava/util/concurrent/ExecutorService;
    :catchall_1
    move-exception v2

    :try_start_4
    invoke-interface {v1}, Ljava/util/concurrent/ExecutorService;->shutdownNow()Ljava/util/List;

    throw v2
    :try_end_4
    .catchall {:try_start_4 .. :try_end_4} :catchall_0
.end method
